package day10;

import java.awt.List;
import java.util.ArrayList;
import java.util.Scanner;

import day9.Student;

public class xueshengguanli {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		ArrayList<Student> list = new ArrayList<Student>();
		while (true) {

			System.out.println("请输入学生姓名");
			String name = sc.next();
			System.out.println("请输入学生ID");
			int id = sc.nextInt();
			Student student = new Student(name, id);

			list.add(student);
			System.out.println("如果想退出请按0 按其他键继续");
			int quit = sc.nextInt();

			if (quit == 0) {
				break;

			}

		}
		while (true) {

			System.out.println("根据id查找输入：1");
			System.out.println("根据名字查找输入：2");

			System.out.println("退出程序：0");

			int type = sc.nextInt();
			if (type == 0) {
				System.out.println("退出程序");
				break;
			}

			switch (type) {
			case 1:
				System.out.println("根据id搜索");
				boolean isSearchByIdFound = false;
				int searchId = sc.nextInt();
				for (Student student : list) {
					if (student.getId() == searchId) {
						System.out.println(student);
						isSearchByIdFound = true;
						break;
					}
				}
						if (isSearchByIdFound = false) {
							System.out.println("没有找到这个人");
							break;
						}
					
				
				break;
			case 2:
				System.out.println("根据姓名查找");
				boolean isSearchByNameFound = false;
				String searchname = sc.next();
				for (Student student : list) {
					if (student.getName().equals(searchname)) {
						System.out.println(student);
						isSearchByNameFound = true;
						break;
					}
						if(isSearchByNameFound =false) {
							System.out.println("没有找到这个人");
							break;
						}
						
					}
				break;
				default:
				break;
				
					
				}

			}
		}
	}

